package com.own.business.question.entity.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.common.handler.ReplyEnvironmentHandler;
import com.own.business.question.common.serializer.ReplyEnvironmentSerializer;
import com.own.business.question.entity.po.PracticeHistory;
import com.own.component.common.base.entity.vo.BaseModifiedSortVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * PracticeHistoryVo
 *
 * @author chenxueli
 * @date 2021/05/14 15:49:28
 */
@Schema(description = "练习流水表" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class PracticeHistoryVo extends BaseModifiedSortVo<PracticeHistory> {

    @Schema(description = "用户id")
    private Long userId;

    @Schema(description = "练习id")
    private Long practiceId;

    @Schema(description = "题目id")
    private Long questionId;

    @Schema(description = "判定结果 0-1")
    private BigDecimal judging;

    @Schema(description = "用户答案")
    private String answer;

    @Schema(description = "题目用时（ms）")
    private Long useTime;

    @Schema(description = "作答环境")
    @TableField(typeHandler = ReplyEnvironmentHandler.class)
    @JsonSerialize(using = ReplyEnvironmentSerializer.class)
    private ReplyEnvironment replyEnvironment;

    @Schema(description = "作答状态 0=未作答 1=已作答 2=保存 3=废弃")
    private Integer status;

    @Schema(description = "答案的打乱顺序")
    private String keySortOrder;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public PracticeHistoryVo(@NonNull PracticeHistory entity) {
        super(entity);
        this.userId = entity.getFkUserId();
        this.practiceId = entity.getFkPracticeId();
        this.questionId = entity.getFkQuestionId();
        this.judging = entity.getJudging();
        this.answer = entity.getAnswer();
        this.useTime = entity.getUseTime();
        this.replyEnvironment = entity.getReplyEnvironment();
        this.status = entity.getStatus();
        this.keySortOrder = entity.getKeySortOrder();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public PracticeHistory toPo(PracticeHistory entity) {
        if (entity == null) {
            entity = new PracticeHistory();
        }
        entity.setFkUserId(this.userId);
        entity.setFkPracticeId(this.practiceId);
        entity.setFkQuestionId(this.questionId);
        entity.setJudging(this.judging);
        entity.setAnswer(this.answer);
        entity.setUseTime(this.useTime);
        entity.setReplyEnvironment(this.replyEnvironment);
        entity.setStatus(this.status);
        entity.setKeySortOrder(this.keySortOrder);
        return super.toPo(entity);
    }

}
